package com.Lixiaoqian.CardPlay.utils;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v4.app.FragmentActivity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;

import com.Lixiaoqian.CardPlay.base.MyApp;
import com.Lixiaoqian.CardPlay.common.customview.CustomDialogFragment;


public class DialogUtils {

	private static Toast mToast;
	private static Toast mToastAR;
	private static Toast mToastARLBS;
	private static ProgressDialog progressDialog;
	private static CustomDialogFragment callDialog;

	public static void showNotitleDialog(Context context,String Message, DialogInterface.OnClickListener pobutton){
		final AlertDialog.Builder alert=new AlertDialog.Builder(context);
		alert.setTitle("提示");
		alert.setMessage(Message);
		alert.setNegativeButton("取消", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
			}
		});
		alert.setPositiveButton("确定",pobutton);
		alert.create().show();
	}

	/**
	 * Toast提示
	 * @param context
	 * @param msgId
	 */
	public static void showToast(Context context, int msgId) {
		if (mToast == null) {
			mToast = Toast.makeText(context, msgId, Toast.LENGTH_SHORT);
		} else {
			mToast.setText(msgId);
		}
		mToast.setGravity(Gravity.CENTER, 0, 0);
		mToast.show();
	}


	/**
	 * 自定义Toast的View
	 * @param context
	 */
	public static void showToastLBS(Context context, int layoutid) {
		if (mToastARLBS == null) {
			mToastARLBS = Toast.makeText(context, "", Toast.LENGTH_SHORT);
			View view =LayoutInflater.from(context).inflate(layoutid, null);
			mToastARLBS.setView(view);
		}
		mToastARLBS.setGravity(Gravity.CENTER, 0, 0);
		mToastARLBS.show();
	}



	/**
	 * 关闭进度条自定义对话框
	 */
	public static void dismissProgress() {
		// if (progressDialog != null && progressDialog.isShowing()) {
		// progressDialog.dismiss();
		// }
		if (MyApp.getSdkVersion()<20) {
			return;
		}

			if (callDialog != null) {
				callDialog.dismiss();
			}


	}


	/**
	 * 自定义数据访问提示 无标题就一个圈圈和加载中...
	 * @param context
	 */
	public static void showCustomDialogFragment(Context context) {
		if (MyApp.getSdkVersion()<20) {
			return;
		}
		callDialog = CustomDialogFragment.newInstance(0);
		callDialog.show(
				((FragmentActivity) context).getSupportFragmentManager(),
				"custom");
	}

}
